#!/usr/bin/env jruby
# -*- coding: us-ascii -*-
# Elizabeth Wiethoff 2008

require 'java'
require 'pp' if $DEBUG

[
  'java.awt.BorderLayout',  # default for JFrame
  'java.awt.CardLayout', 
  'java.awt.Dimension', 
  'java.awt.FlowLayout',  # default for JPanel
  'java.awt.GridBagLayout', 
  'java.awt.GridLayout', 
  'javax.swing.BorderFactory', 
  'javax.swing.Box',  # use instead of BoxLayout
  'javax.swing.BoxLayout', 
  'javax.swing.JButton', 
  'javax.swing.JCheckBox', 
  'javax.swing.JFrame', 
  'javax.swing.JLabel', 
  'javax.swing.JPanel', 
  'javax.swing.JScrollPane', 
].each do |klass|
  begin
    include_class klass
  rescue StandardError => e
    puts e
  end
end

########################################

def assembleDialog(dialog, title, checkbox, label, button)
  layout = BorderLayout.new
  layout.setVgap(5)
  dialog.setLayout(layout)
  
  pButton = JPanel.new
  pButton.add(button)
  
  label.setVerticalAlignment(JLabel::TOP)
  spLabel = JScrollPane.new(label)
  spLabel.setPreferredSize(Dimension.new(450, 50))
  spLabel.setMinimumSize(spLabel.getPreferredSize)
  spLabel.setMaximumSize(Dimension.new(9999, 9999))
  
  checkbox.setHorizontalTextPosition(JCheckBox::LEADING)
  checkbox.setHorizontalAlignment(JCheckBox::RIGHT)
  checkbox.setEnabled(true)
  
  dialog.setBorder(BorderFactory.createTitledBorder(title))
  dialog.add(checkbox, BorderLayout::NORTH)
  dialog.add(spLabel, BorderLayout::CENTER)
  dialog.add(pButton, BorderLayout::SOUTH)
  
  return dialog
end

########################################

dialog1 = assembleDialog(
  JPanel.new,  # need to create CB's enclosure before the CB!
  'Reference Directory', 
  checkbox = JCheckBox.new('Include subdirecories', true), 
  JLabel.new('<none>'), 
  JButton.new('Set Reference Directory...')
)

dialog2 = assembleDialog(
  JPanel.new,  # need to create CB's enclosure before the CB!
  'Directory To Search', 
  checkbox = JCheckBox.new('Include subdirecories', true), 
  JLabel.new('<none><none><none><none><none><none><none><none><none>'), 
  JButton.new('Set Directory To Search...')
)

dialogs = JPanel.new(GridLayout.new(2, 1))
dialogs.add(dialog1)
dialogs.add(dialog2)

########################################

pGoButton = JPanel.new(FlowLayout.new(FlowLayout::CENTER, 25, 5))
pGoButton.add(JButton.new('Cancel'))
pGoButton.add(JButton.new('Search'))

########################################

mainFrame = JFrame.new('SuperElse Busy Box Layout')
mainFrame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)

mainContentPane = mainFrame.getContentPane()
mainContentPane.setLayout(BorderLayout.new)
mainContentPane.add(dialogs, BorderLayout::CENTER)
mainContentPane.add(pGoButton, BorderLayout::SOUTH)

mainFrame.pack()
mainFrame.setVisible(true)
